<template>
  <el-dialog
    :title="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="JADP-dialog JADP-dialog_center"
    lock-scroll
    width="600px"
  >
    <el-row :gutter="15" class="">
      <el-form
        ref="elForm"
        :model="dataForm"
        :rules="rules"
        size="small"
        label-width="100px"
        label-position="right"
        :disabled="!!isDetail"
      >
        <el-col :span="24">
          <el-form-item label="班级主键" prop="class_id">
            <el-input
              v-model="dataForm.class_id"
              placeholder="请输入"
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item
            label="关联考试类型(模拟，正式)"
            prop="examination_type"
          >
            <el-radio-group v-model="dataForm.examination_type" size="small">
              <el-radio
                v-for="(item, index) in examination_typeOptions"
                :key="index"
                :label="item.id"
                :disabled="item.disabled"
              >
                {{ item.fullName }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="考试id" prop="examination_id">
            <el-input
              v-model="dataForm.examination_id"
              placeholder="请输入"
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="考试状态" prop="status">
            <el-radio-group v-model="dataForm.status" size="small">
              <el-radio
                v-for="(item, index) in statusOptions"
                :key="index"
                :label="item.id"
                :disabled="item.disabled"
              >
                {{ item.fullName }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="创建用户" prop="creatoruserid">
            <el-input
              v-model="dataForm.creatoruserid"
              placeholder="系统自动生成"
              readonly
            >
            </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="创建时间" prop="creatortime">
            <el-input
              v-model="dataForm.creatortime"
              placeholder="系统自动生成"
              readonly
            >
            </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="修改用户" prop="lastmodifyuserid">
            <el-input
              v-model="dataForm.lastmodifyuserid"
              placeholder="系统自动生成"
              readonly
            >
            </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="修改时间" prop="lastmodifytime">
            <el-input
              v-model="dataForm.lastmodifytime"
              placeholder="系统自动生成"
              readonly
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import request from "@/utils/request";
import { getDictionaryDataSelector } from "@/api/systemData/dictionary";
import { previewDataInterface } from "@/api/systemData/dataInterface";
import ExportBox from "./ExportBox";
export default {
  components: { ExportBox },
  props: [],
  data() {
    return {
      loading: false,
      visible: false,
      isDetail: false,
      activeName: "",
      dataForm: {
        class_id: undefined,
        examination_type: "",
        examination_id: undefined,
        status: "",
        creatoruserid: "",
        creatortime: "",
        lastmodifyuserid: "",
        lastmodifytime: "",
        organizeId:""
      },
      rules: {},
      examination_typeOptions: [],
      statusOptions: [],
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getexamination_typeOptions();
    this.getstatusOptions();
  },
  mounted() {},
  methods: {
    getexamination_typeOptions() {
      getDictionaryDataSelector("56465a402e384eed909b6bc6d957ae57").then(
        (res) => {
          this.examination_typeOptions = res.data.list;
        }
      );
    },
    getstatusOptions() {
      getDictionaryDataSelector("70355c1310a6411391ff41e80ee039f9").then(
        (res) => {
          this.statusOptions = res.data.list;
        }
      );
    },
    init(id, isDetail) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.isDetail = isDetail || false;
      this.$nextTick(() => {
        this.$refs["elForm"].resetFields();
        if (this.dataForm.id) {
          this.loading = true;
          request({
            url:
              `/api/xy_ks_class_examination/Xy_ks_class_examination/${this.dataForm.id}?organizeId=${this.$store.getters.organizeId}`
              ,
            method: "get",
          }).then((res) => {
            this.dataForm = res.data;
            this.loading = false;
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          this.dataForm.organizeId= this.$store.getters.organizeId;
          if (!this.dataForm.id) {
            request({
              url: `/api/xy_ks_class_examination/Xy_ks_class_examination`,
              method: "post",
              data: this.dataForm,
            }).then((res) => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  (this.visible = false), this.$emit("refresh", true);
                },
              });
            });
          } else {
            request({
              url:
                "/api/xy_ks_class_examination/Xy_ks_class_examination/" +
                this.dataForm.id,
              method: "PUT",
              data: this.dataForm,
            }).then((res) => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refresh", true);
                },
              });
            });
          }
        }
      });
    },
  },
};
</script>




